home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 3_0 / SPIRO_SO / ABOUT.C next >
Text File  |  1989-06-17  |  7KB  |  418 lines

  1.  
  2. /*
  3. (c) copyright 1988 Symantec Corporation.  For use with THINK's Lightspeed C only.
  4.  
  5. You may incorporate these routines in any of your programs, for commercial distribution
  6. or otherwise, but you may not charge for the specific use of this code.  Symantec 
  7. Corporation makes no warranty regarding the fitness of this software for any particular
  8. purpose.
  9.  
  10. about.c -- a generic "about" box for any Macintosh program written in Lightspeed C.
  11.  
  12. To use this, just define the strings below, add the file to your project, and
  13. call "aboutcommand" from your menu handling procedure.
  14.  
  15. Not too big, kind of sexy, and certainly better than nothing!
  16.  
  17. Thanks to Galen Babcock and Apple Computer...
  18.  
  19. First upload to LVTFORUM on Compuserve by Dave Winer: 1/24/88
  20. */ 
  21.  
  22. #define line1 "\pJohn's Fabulous Spiro-Program"
  23. #define line2 "\pWritten by John Nalezny"
  24. #define line3 "\pCompuserve 72137,1212"
  25. #define line4 "\pVersion 1.0"
  26. #define line5 "\pJune 17 1989"
  27. #define line6 "\pCatch the ~ !"
  28.  
  29.  
  30. #include "MacTypes.h"  
  31. #include "QuickDraw.h" 
  32. #include "EventMgr.h"
  33. #include "DialogMgr.h"
  34. #include "FontMgr.h"
  35.  
  36. #include "standard.h" 
  37.  
  38.  
  39. #define zoomfixer 65536L
  40.  
  41. #define zoomsteps 16
  42.  
  43. Fixed zoomfract;
  44.  
  45. #define ctportstackelements 10 /*we can remember ports up to 10 levels deep*/
  46.  
  47. #define maxportstack 9 /*this is the highest valid index in the port stack*/
  48.  
  49. int topportstack;
  50.  
  51. GrafPtr portstack [ctportstackelements];
  52.  
  53. #if 0
  54. initmacintosh () {
  55.  
  56.     /*
  57.     the magic stuff that every macintosh application needs to do 
  58.     before doing anything else.
  59.     */
  60.  
  61.     register int i;
  62.         
  63.     MaxApplZone ();
  64.     
  65.     for (i = 1; i < 11; i++) 
  66.         MoreMasters ();
  67.  
  68.     InitGraf (&thePort);
  69.     
  70.     InitFonts ();
  71.     
  72.     FlushEvents (everyEvent, 0);
  73.     
  74.     InitWindows ();
  75.     
  76.     InitMenus ();
  77.     
  78.     TEInit ();
  79.     
  80.     InitDialogs (nil);
  81.     
  82.     InitCursor();
  83.     } /*initmacintosh*/
  84. #endif    
  85.     
  86. pushport (p) GrafPtr p; {
  87.  
  88.     if (topportstack < maxportstack) /*room left to push something*/
  89.     
  90.         portstack [topportstack++] = thePort;
  91.     
  92.     if (p != nil)
  93.         SetPort (p);
  94.     } /*pushport*/
  95.         
  96.  
  97. popport () {
  98.  
  99.     if (topportstack > 0)  /*there's something in the stack to pop*/
  100.     
  101.         SetPort (portstack [--topportstack]);
  102.     } /*popport*/
  103.             
  104.             
  105. localtoglobalrect (r) Rect *r; {
  106.  
  107.     Point p1, p2;
  108.  
  109.     p1 = topLeft (*r);
  110.     
  111.     p2 = botRight (*r);
  112.     
  113.     LocalToGlobal (&p1);
  114.     
  115.     LocalToGlobal (&p2);
  116.     
  117.     Pt2Rect (p1, p2 ,r);
  118.     } /*localtoglobalrect*/
  119.     
  120.  
  121. int blend (i1, i2) int i1, i2; {
  122.  
  123.     Fixed smallFix,bigFix,tempFix;
  124.  
  125.     smallFix = zoomfixer * i1;
  126.     
  127.     bigFix = zoomfixer * i2;
  128.     
  129.     tempFix = FixMul(zoomfract,bigFix)+FixMul(zoomfixer-zoomfract,smallFix);
  130.     
  131.     return(FixRound(tempFix));
  132.     } /*blend*/
  133.     
  134.  
  135. zoomrect (smallrect, bigrect, zoomup)
  136.  
  137.     Rect *smallrect,*bigrect;
  138.     boolean    zoomup;
  139.     
  140.     {
  141.     Fixed factor;
  142.     Rect rect1,rect2,rect3,rect4;
  143.     GrafPtr savePort,deskPort;
  144.     int i;
  145.     
  146.     GetPort (&savePort);
  147.     
  148.     OpenPort (deskPort = (GrafPtr) NewPtr (sizeof (GrafPort)));
  149.     
  150.     InitPort (deskPort);
  151.     
  152.     SetPort (deskPort);
  153.     
  154.     PenPat (gray);
  155.     
  156.     PenMode (notPatXor);
  157.     
  158.     if (zoomup) {
  159.     
  160.         rect1 = *smallrect;
  161.         
  162.         factor = FixRatio(6,5);
  163.         
  164.         zoomfract = FixRatio(541,10000);
  165.         }
  166.     else {
  167.         rect1 = *bigrect;
  168.         
  169.         factor = FixRatio(5,6);
  170.         
  171.         zoomfract = zoomfixer;
  172.         }
  173.         
  174.     rect2 = rect1;
  175.     
  176.     rect3 = rect1;
  177.     
  178.     FrameRect (&rect1);
  179.     
  180.     for (i = 1; i<= zoomsteps; i++) {
  181.     
  182.         rect4.left = blend (smallrect->left, bigrect->left);
  183.         
  184.         rect4.right = blend (smallrect->right, bigrect->right);
  185.         
  186.         rect4.top = blend (smallrect->top, bigrect->top);
  187.         
  188.         rect4.bottom = blend (smallrect->bottom, bigrect->bottom);
  189.         
  190.         FrameRect (&rect4);
  191.         
  192.         FrameRect (&rect1);
  193.         
  194.         rect1 = rect2;
  195.         
  196.         rect2 = rect3;
  197.         
  198.         rect3 = rect4;
  199.          
  200.         zoomfract = FixMul (zoomfract,factor);
  201.         } /*for*/
  202.         
  203.     FrameRect (&rect1);
  204.     
  205.     FrameRect (&rect2);
  206.     
  207.     FrameRect (&rect3);
  208.     
  209.     ClosePort (deskPort);
  210.     
  211.     DisposPtr ((Ptr)deskPort);
  212.     
  213.     PenNormal ();
  214.     
  215.     SetPort (savePort);
  216.     } /*zoomrect*/
  217.     
  218.     
  219. zoomport (w, flup) WindowPtr w; boolean flup; {
  220.  
  221.     /*
  222.     Zooms the window referenced by "w" either from an inivisible
  223.     state to a visible state, or vice versa.  Pass true in the "flup"
  224.     boolean parameter to zoom a window to open, an false to zoom
  225.     it close.  The WindowPtr must have already been created elsewhere,
  226.     and zooming the window invisible only hides the window, it does
  227.     not destroy the WindowPtr data.
  228.     */
  229.     
  230.     Rect r1, r2, r3;
  231.  
  232.     SetPort (w);
  233.     
  234.     SetRect (&r1, 0, 20, 0, 20);
  235.     
  236.     r3 = (*w).portRect;
  237.     
  238.     r2 = r3;
  239.     
  240.     InsetRect (&r2, (r3.right - r3.left + 20) / 2, (r3.bottom - r3.top + 20) / 2);
  241.  
  242.     localtoglobalrect (&r2);
  243.     
  244.     localtoglobalrect (&r3);
  245.  
  246.     if (flup) {
  247.     
  248.         zoomrect (&r1, &r2, true);
  249.         
  250.         zoomrect (&r2, &r3, true);
  251.         
  252.         ShowWindow (w);
  253.         
  254.         SetPort (w);
  255.         }
  256.     else {
  257.         HideWindow (w);
  258.         
  259.         zoomrect (&r2, &r3, false);
  260.         
  261.         zoomrect (&r1, &r2, false);
  262.         }
  263.     } /*zoomport*/
  264.     
  265.     
  266. positionaboutwindow (pdialog, rscreen) WindowPtr pdialog; Rect rscreen; {
  267.  
  268.     int h, v;
  269.     Rect rdialog;
  270.     
  271.     rdialog = (*pdialog).portRect;
  272.     
  273.     h = rscreen.left + (((rscreen.right - rscreen.left) - (rdialog.right - rdialog.left)) / 2);
  274.     
  275.     v = rscreen.top + (((rscreen.bottom - rscreen.top) - (rdialog.bottom - rdialog.top)) / 3);
  276.     
  277.     MoveWindow (pdialog, h, v, false);
  278.     } /*positionaboutwindow*/
  279.     
  280.     
  281. pascalcopy (bssource, bsdest) bigstring *bssource, *bsdest; {
  282.  
  283.     /*
  284.     create a copy of bssource in bsdest.
  285.     */
  286.  
  287.     register int i, len;
  288.     
  289.     for (i = 0; i <= (len = (*bssource) [0]);) 
  290.     
  291.         (*bsdest) [i] = (*bssource) [i++];
  292.     } /*pascalcopy*/
  293.  
  294.  
  295. #define doline(x)\
  296.                                                                             \
  297.     pascalcopy ((ptrstring) x, &bs);                                        \
  298.                                                                             \
  299.     MoveTo (r.left + (r.right - r.left - StringWidth (bs)) / 2, linev);        \
  300.                                                                             \
  301.     DrawString (bs);                                                        \
  302.                                                                             \
  303.     linev += lineinc;
  304.  
  305.  
  306. void drawabout (w) WindowPtr w; {
  307.     
  308.     bigstring bs;
  309.     Rect r;
  310.     int linev = 24;
  311.     int lineinc = 14;
  312.     int index;
  313.     Rect rtext;
  314.     
  315.     r = (*w).portRect;
  316.     
  317.     InsetRect (&r, 4, 4);
  318.     
  319.     TextFont (systemFont);
  320.     
  321.     TextSize (12);
  322.     
  323.     doline (line1);
  324.     
  325.     TextFont (geneva);
  326.     
  327.     TextSize (9);
  328.     
  329.     doline (line2);
  330.     
  331.     doline ("\p");
  332.     
  333.     doline (line3);
  334.     
  335.     doline (line4);
  336.     
  337.     pascalcopy ((ptrstring) line5, &bs);
  338.     
  339.     MoveTo (r.left + 4, r.bottom - 6);
  340.     
  341.     DrawString (bs);
  342.     
  343.     pascalcopy ((ptrstring) line6, &bs);
  344.     
  345.     MoveTo (r.right - StringWidth (bs) - 4, r.bottom - 6);
  346.     
  347.     DrawString (bs);
  348.     } /*drawabout*/
  349.  
  350.  
  351. void aboutcommand () {
  352.  
  353.     GrafPtr eventport;
  354.     Rect r;
  355.     EventRecord ev;
  356.     WindowPtr w;
  357.     boolean flbitmap;
  358.  
  359.     InitCursor ();
  360.     
  361.     SetRect (&r, 0, 0, 340, 120);
  362.     
  363.     pushport (w = NewWindow (nil, &r, "\p", false, altDBoxProc, -1L, false, 0));
  364.         
  365.     positionaboutwindow ((DialogPtr) w, screenBits.bounds);
  366.     
  367.     zoomport (w, true);
  368.     
  369.     drawabout (w);
  370.     
  371.     while (true){
  372.     
  373.         if (!GetNextEvent (everyEvent, &ev))
  374.             continue;
  375.             
  376.         switch (ev.what) {
  377.         
  378.             case keyDown:
  379.             case autoKey:
  380.             case mouseDown:            
  381.                 goto exit;
  382.                 
  383.             case updateEvt:    /*handle updates, he might be using Pyro!*/
  384.             
  385.                 if ((WindowPtr) (ev.message) == w) {
  386.                 
  387.                     pushport (w);
  388.                     
  389.                     BeginUpdate (w);
  390.                     
  391.                     drawabout (w);
  392.                     
  393.                     EndUpdate (w);
  394.                     
  395.                     popport ();
  396.                     }
  397.                                     
  398.                 break;
  399.  
  400.             } /*switch*/
  401.         } /*while*/
  402.         
  403.     exit:
  404.     
  405.     HideWindow (w);
  406.     
  407.     zoomport (w, false);
  408.     
  409.     DisposeWindow (w);
  410.     
  411.     popport ();
  412.     
  413.     FlushEvents (mDownMask + keyDownMask, 0);
  414.     } /*aboutcommand*/
  415.     
  416.     
  417.  
  418.